package main

import (
	"fmt"
	"log"
	"os"

	"github.com/gofiber/fiber/v2"
	"gorm.io/gorm"

	"main/src/routes"
	"main/src/utils"
)

var db *gorm.DB

func init() {
	utils.LoadEnv()
	dsn := os.Getenv("DB_DSN")
	db = utils.ConnectDB(dsn) // Connect to database
	utils.AddSuperAdmin(db, os.Getenv("SU_LOGIN"), os.Getenv("SU_PASS"))
}

func main() {
	app := fiber.New(fiber.Config{
		ProxyHeader: fiber.HeaderXForwardedFor,
	  })

	routes.User(app, db)
	

	if err := app.Listen(":" + os.Getenv("APP_PORT")); err!= nil {
		log.Fatal("App start error: " + err.Error())
	} else {
		fmt.Println("Server listening on port " + os.Getenv("APP_PORT"))
	}
}
